<?php
/**
 * @file
 * Theme setting callbacks for the 6ixfire Arnem theme.
 */
global $base_url;

define('CURRENT_THEME',variable_get('theme_default'));
define('THEME_PATH',drupal_get_path('theme','solveto'));
drupal_add_js(THEME_PATH . '/js/admin/jquery.cookie.js');

// Add media browser js
if(module_exists('media')) {
    static $included;

    if ($included) {
        return;
    }
    $included = TRUE;
    module_load_include('inc', 'media', 'includes/media.browser');
    $javascript = media_browser_js();
    foreach ($javascript as $key => $definitions) {
        foreach ($definitions as $definition) {
            $function = 'drupal_add_' . $key;
            call_user_func_array($function, $definition);
        }
    }
// Add wysiwyg-specific settings.
    $settings = array('wysiwyg_allowed_attributes' => variable_get('media__wysiwyg_allowed_attributes', array('height', 'width', 'hspace', 'vspace', 'border', 'align', 'style', 'class', 'id', 'usemap', 'data-picture-group', 'data-picture-align')));
    drupal_add_js(array('media' => $settings), 'setting');
}


drupal_add_library('system', 'ui.widget');
drupal_add_library('system', 'ui.collapsible');
drupal_add_library('system', 'ui.mouse');
drupal_add_library('system', 'ui.slider');
drupal_add_library('system', 'ui.tabs');
drupal_add_library('system', 'ui.dialog');
drupal_add_library('system', 'ui.draggable');
drupal_add_library('system', 'ui.sortable');
drupal_add_library('system', 'ui.slider');
drupal_add_library('system', 'ui.accordion');

drupal_add_js(array('baseUrl' => $base_url),'setting');

drupal_add_css(THEME_PATH . '/css/admin/reset.css', array('group' => CSS_THEME));
drupal_add_css(THEME_PATH . '/css/admin/bootstrap.css', array('group' => CSS_THEME));
drupal_add_css(THEME_PATH . '/css/admin/font-awesome.min.css', array('group' => CSS_THEME));
drupal_add_css(THEME_PATH . '/css/admin/spectrum.css', array('group' => CSS_THEME));
drupal_add_css(THEME_PATH . '/css/admin/bootstrap-dialog.css', array('group' => CSS_THEME));
drupal_add_css(THEME_PATH . '/css/admin/main.css', array('group' => CSS_THEME));
drupal_add_css(THEME_PATH . '/css/admin/ui-custom.css', array('group' => CSS_THEME));
drupal_add_css(THEME_PATH . '/css/admin/theme-drupal.css', array('group' => CSS_THEME));

drupal_add_js(THEME_PATH . '/js/admin/jquery-migrate-1.2.1.js');
drupal_add_js(THEME_PATH . '/js/admin/bootstrap.min.js');
drupal_add_js(THEME_PATH . '/js/admin/spectrum.js');
drupal_add_js(THEME_PATH . '/js/admin/jquery.collapsible.min.js');
drupal_add_js(THEME_PATH . '/js/admin/uniform.js');
drupal_add_js(THEME_PATH . '/js/admin/bootstrap-dialog.js');
drupal_add_js(THEME_PATH . '/js/admin/jquery.choosefont.js');
drupal_add_js(THEME_PATH . '/js/admin/unlimited-settings.js');

drupal_add_js(THEME_PATH . '/js/admin/script.js');




require_once DRUPAL_ROOT . '/' . THEME_PATH . '/inc/admin/form.inc';
require_once DRUPAL_ROOT . '/' . THEME_PATH . '/inc/admin/general.inc';
require_once DRUPAL_ROOT . '/' . THEME_PATH . '/inc/admin/skin.inc';
require_once DRUPAL_ROOT . '/' . THEME_PATH . '/inc/admin/footer.inc';
require_once DRUPAL_ROOT . '/' . THEME_PATH . '/inc/admin/text.inc';
require_once DRUPAL_ROOT . '/' . THEME_PATH . '/inc/admin/code.inc';
require_once DRUPAL_ROOT . '/' . THEME_PATH . '/inc/admin/config.inc';

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * @param $form
 *   The form.
 * @param $form_state
 *   The form state.
 */

function solveto_form_system_theme_settings_alter(&$form, &$form_state, $form_id = NULL, $no_js_use = FALSE) {
    global $base_url;
    drupal_add_js(array('themePath' => $base_url.'/'.THEME_PATH),'setting');
    if(isset($form_id)){
        return;
    }
    //kpr($form['actions']);die;
    unset($form['theme_settings']);
    //hide($form['actions']);
    hide($form['logo']);
    hide($form['favicon']);
    // Make default dialog markup for icon
    icon_default_dialog();
    $form['html_header'] = array(
        '#markup' => '<div id="main-settings">',

    );
    $form['solveto_settings']['html_open'] = array(
        '#markup' => '<!-- Left side content -->
<div id="leftSide">

    <!-- Left navigation -->
    <ul id="menu" class="nav list-unstyled">
        <li class="general"><a href="#sf-general" title=""  class="exp main-tab"><span>General Settings</span><strong>+</strong></a>
            <ul class="sub nav nested-tab list-unstyled">
                <li><a href="#general-settings" class="sub-tab" ">Sites Default Settings</a></li>
                <li><a href="#logo-favicon-webclip" class="sub-tab">Logo, Favicon &amp; Webclip IOS</a></li>

            </ul>
        </li>
        <li class="skin"><a href="#sf-skin" title="" class="main-tab"><span>Skin Options</span></a>

        <li class="footer"><a href="#sf-footer" title="" class="main-tab"><span>Footer Options</span></a>

        </li>

        <li class="text-typo"><a href="#sf-text-typography" title="" class="exp main-tab"><span>Text & Typography Settings</span><strong>+</strong></a>
            <ul class="sub nav nested-tab list-unstyled">
                <li><a class="sub-tab" href="#custom-font" class="sub-tab">Custom Font</a></li>
                <li><a class="sub-tab" href="#tt-text" >Text &amp; Links</a></li>
                <li><a class="sub-tab" href="#tt-typography" ></i>Typography</a></li>

            </ul>
        </li>
        <li class="code"><a href="#sf-code" title="" class="exp main-tab"><span>Code Settings</span></a>

        </li>
        <li class="config"><a href="#sf-config" title="" class="exp main-tab"><span>Backup & Restore Settings</span><strong>+</strong></a>
            <ul class="sub nav nested-tab list-unstyled">
                <li><a class="sub-tab" href="#config-backup" >Backup Theme Settings</a></li>
                <li><a class="sub-tab" href="#config-restore" >Restore Theme Settings</a></li>
            </ul>
        </li>
    </ul>
</div>

<!-- Right side -->
    <div id="rightSide">
        <div class="wrapper">',
        '#weight' => -99,
    );
    solveto_theme_settings_general($form, $form_state);;
    solveto_theme_settings_skin($form, $form_state);;
    solveto_theme_settings_footer($form, $form_state);
    solveto_theme_settings_text($form, $form_state);
    solveto_theme_settings_code($form, $form_state);
    solveto_theme_settings_config($form, $form_state);
    $form['solveto_settings']['html_close'] = array(
        '#markup' => '</div>
                    </div>'
    ,
        '#weight'       => 97,
    );
    $form['html_footer'] = array(
        '#markup'   => '</div>',
    );


    $form['actions']['reset']      = array(
        '#type'         => 'submit',
        '#value'        => t('Reset Settings'),
        '#submit'       => array('solveto_reset_settings_submit'),
        '#weight'       => 98,
        '#attributes'   => array(
            'class' => array('wButton redB'),
            'onClick'   => 'return confirm("Are you sure want to reset all settings to default ?")'
        )
    );
    $form['actions']['submit']['#weight'] = 97;
    $form['actions']['submit']['#attributes'] = array(
        'class' => array('wButton blueB'),
    );
    $form['actions']['#prefix'] = '<div id="submit-footer" class="footer">';
    $form['actions']['#suffix'] = '</div>';

    // Load font styles
    $fonts = load_font_configure();
    drupal_add_js(array('font_array' => $fonts[0]), 'setting');
    drupal_add_js(array('font_vars' => $fonts[1]), 'setting');
    // add for fonts END
    $form['#validate'][] = 'solveto_validate_theme_settings';
    $form['#submit'][] = 'solveto_save_settings_submit';
}

/**
 * Custom validation for solveto theme setting
 */
function solveto_validate_theme_settings($form, &$form_state) {

}


/**
 * Final submit handler.
 *
 * Reports what values were finally set.
 */

function solveto_save_settings_submit($form, &$form_state) {
    // Exclude unnecessary elements before saving.
    form_state_values_clean($form_state);
    kpr(form_state_values_clean($form_state));
    //Save image file upload via drupal form
    foreach($form_state['values'] as $key => $value) {
        if(strpos($key,'_form_file') !== false) {
            if(isset($form_state['values'][''.str_replace('_form_file','_upload_file',$key).''])) {
                $form_state['values'][$key] = saveImage($form_state['values'][$key],str_replace('_form_file','_upload_file',$key));
            }
        }
    }
    $values = $form_state['values'];
    //kpr($form_state);die;
    // Extract the name of the theme from the submitted form values, then remove
    // it from the array so that it is not saved as part of the variable.
    $theme_key = $values['var'];
    unset($values['var']);

    $form_input = $form_state['input'];
    $form_state['values']['hd_image_slide'] = array();
    $form_state['values']['hd_ct'] = array();
    $form_state['values']['ft_social'] = array();
    $form_state['values']['contact_info'] = array();

    foreach($form_state['input'] as $key => $value) {
        // Header Image Slide
        $hd_image_slide_match = "/hd_image_slide_order/i";
        // Header Maximage Slide
        if(preg_match($hd_image_slide_match,$key)) {
            $explode = explode("|",$value);
            foreach($explode as $key2 => $value2) {
                $new_key = str_replace("-","_",$value2);
                $new_explode = explode("_",$new_key);
                end($new_explode);
                $number = current($new_explode);
                if($new_key != null) {
                    $form_state['values']['hd_image_slide'][$new_key]['image'] = $form_state['input']['hd_image_slide_upload_'.$number];
                }
            }
        }
        // Header Content
        $hd_ct_match = "/hd_ct_order/i";
        if(preg_match($hd_ct_match,$key)) {
            $explode = explode("|",$value);
            foreach($explode as $key2 => $value2) {
                $new_key = str_replace("-","_",$value2);
                $new_explode = explode("_",$new_key);
                end($new_explode);
                $number = current($new_explode);
                if($new_key != null) {
                    $form_state['values']['hd_ct'][$new_key]['big_text'] = $form_state['input']['hd_ct_big_text_'.$number];
                    $form_state['values']['hd_ct'][$new_key]['sub_text'] = $form_state['input']['hd_ct_sub_text_'.$number];
                    $form_state['values']['hd_ct'][$new_key]['title'] = $form_state['input']['hd_ct_title_'.$number];
                    $form_state['values']['hd_ct'][$new_key]['button_text'] = $form_state['input']['hd_ct_button_text_'.$number];
                    $form_state['values']['hd_ct'][$new_key]['button_link'] = $form_state['input']['hd_ct_button_link_'.$number];
                }
            }
        }
        //Footer Social
        $ft_social_match = "/ft_social_order/i";
        if(preg_match($ft_social_match,$key)) {
            $explode = explode("|",$value);
            foreach($explode as $key2 => $value2) {
                $new_key = str_replace("-","_",$value2);
                $new_explode = explode("_",$new_key);
                end($new_explode);
                $number = current($new_explode);
                if($new_key != null) {
                    $icon_input = $form_input['ft_social_icon_'.$number]['icon'];
                    if($icon_input != null){
                        $ft_sc_icon_explode = explode("|",$icon_input);
                        $form_state['values']['ft_social'][$new_key]['icon']['bundle'] = $ft_sc_icon_explode[0];
                        $form_state['values']['ft_social'][$new_key]['icon']['icon'] = $ft_sc_icon_explode[1];
                    }
                    $form_state['values']['ft_social'][$new_key]['link'] = $form_input['ft_social_link_'.$number] ? $form_input['ft_social_link_'.$number] : '';

                }
            }
        }
        //Footer Detail
        $contact_info_match = "/contact_info_order/i";
        if(preg_match($contact_info_match,$key)) {
            $explode = explode("|",$value);
            foreach($explode as $key2 => $value2) {
                $new_key = str_replace("-","_",$value2);
                $new_explode = explode("_",$new_key);
                end($new_explode);
                $number = current($new_explode);
                if($new_key != null) {
                    $icon_input = $form_input['contact_info_icon_'.$number]['icon'];
                    if($icon_input != null){
                        $contact_info_icon_explode = explode("|",$icon_input);
                        $form_state['values']['contact_info'][$new_key]['icon']['bundle'] = $contact_info_icon_explode[0];
                        $form_state['values']['contact_info'][$new_key]['icon']['icon'] = $contact_info_icon_explode[1];
                    }
                    $form_state['values']['contact_info'][$new_key]['detail'] = $form_input['contact_info_detail_'.$number] ? $form_input['contact_info_detail_'.$number] : '';

                }
            }
        }
    }

    $form_state['#rebuild'] = true;
    cache_clear_all();
}
function saveImage($path, $upload) {
    $validators = array('file_validate_extensions' => array('ico png gif jpg jpeg apng svg'));
    $save_path = $path;
    if($file = file_save_upload($upload,$validators)) {
        if (isset($file)) {
            // File upload was attempted.
            if ($file) {
                $parts = pathinfo($file->filename);
                $destination = 'public://' . $parts['basename'];
                $file->status = FILE_STATUS_PERMANENT;
                if (file_copy($file, $destination, FILE_EXISTS_REPLACE)) {
                    $save_path = $parts['basename'];
                }
            }
            else {
                // File upload failed.
                form_set_error(key($path), t('File could not be uploaded.'));
            }
        } else {
            $save_path = $path;
        }
    } else {
        $save_path = $path;
    }
    return $save_path;
}
/**
 * @param $form
 * @param $form_state
 * Reset all theme settings
 */
function solveto_reset_settings_submit($form, &$form_state){
    $theme_settings = variable_get('theme_solveto_settings');
    $default_settings = _solveto_theme_default_settings($theme_settings);
    variable_set('theme_solveto_settings',null);
    variable_set('theme_solveto_settings',$default_settings);
    drupal_set_message('All settings reset to default');
    cache_clear_all();
}
/**
 * Backup Theme Settings
 */
function solveto_backup_theme_settings() {
    global $theme_key;
    $theme_settings = variable_get('theme_solveto_settings');
    $current_time = time();
    $cv_datetime = date("Y-m-d",$current_time);
    $backup_file = serialize(base64_encode(drupal_json_encode($theme_settings)));
    $bu_folder = 'public://solveto_backup';
    if(file_prepare_directory($bu_folder) === false) {
        drupal_mkdir($bu_folder);
    }
    if (file_unmanaged_save_data($backup_file, $bu_folder . '/'.str_replace('_','-','solveto').'-backup-'.$cv_datetime.'-'.$current_time.'.txt', FILE_EXISTS_REPLACE) === FALSE) {
        drupal_set_message(t("Could not create backup file."));
        return;
    } else {
        drupal_set_message(t("Backup Theme Settings Successful!"));
        drupal_set_message(t("Your backup settings is stored in ".file_create_url(''.$bu_folder.'/'.str_replace('_','-','solveto').'-backup-'.$cv_datetime.'-'.$current_time.'.txt').""));
    }
}
/**
 * Restore Theme settings
 */
function solveto_restore_theme_settings($form, &$form_state) {
    $values = $form_state['values'];
    if($values['restore_type'] !=  null) {

        if($values['restore_type'] == 'upload') {
            if($form_state['values']['restore_file_media_upload']['fid'] != 0) {
                $file = file_load($form_state['values']['restore_file_media_upload']['fid']);
                if($file == false) {
                    drupal_set_message(t("Your file upload isn't found, please upload again"),'warning');
                    return;
                }
                if(strpos((string)($file->filename), '*/'.str_replace('_','-','solveto').'-backup/*') !== FALSE) {
                    $file_content = file_get_contents($file->uri);
                    $restore_settings = drupal_json_decode(base64_decode(unserialize($file_content)));
                    if(is_array($restore_settings)) {
                        variable_set('theme_solveto_settings',array());
                        variable_set('theme_solveto_settings',$restore_settings);
                        file_delete($file,$force = true);
                        cache_clear_all();
                        drupal_set_message(t('All your theme settings have been restored'));
                    } else {
                        drupal_set_message(t("Your file upload isn't correct, please upload again"),'warning');
                        return;
                    }
                } else {
                    drupal_set_message(t("Your file upload isn't this theme backup types, please upload again"),'warning');
                    return;
                }

            } else {
                drupal_set_message(t('Please choose your file upload'),'error');
                return;
            }
        } else {
            if($values['restore_from_file'] == null) {
                drupal_set_message('Choose your backup file in list or move back up to backup folder','warning');
                return;
            } else {
                if(strpos((string)($values['restore_from_file']), '*/'.str_replace('_','-','solveto').'-backup/*') !== FALSE) {
                    $file_content = file_get_contents("public://solveto_backup/{$values['restore_from_file']}");
                    $restore_settings = drupal_json_decode(base64_decode(unserialize($file_content)));
                    if(is_array($restore_settings)) {
                        variable_set('theme_solveto_settings',array());
                        variable_set('theme_solveto_settings',$restore_settings);
                        cache_clear_all();
                        drupal_set_message(t('All your theme settings have been restored'));
                    } else {
                        drupal_set_message(t("Your choosen backup file isn't correct, please choose again"),'warning');
                        return;
                    }
                } else {
                    drupal_set_message(t("Your choosen backup file isn't this theme backup types, please choose again"),'warning');
                    return;
                }
            }



        }
    }



    if ($restore_file = file_save_upload('restore_file_simple_upload')) {
        $file_content = file_get_contents($restore_file->uri);
        $restore_settings = drupal_json_decode(base64_decode(unserialize($file_content)));
        variable_set('theme_solveto_settings',$restore_settings);
        cache_clear_all();
        drupal_set_message(t('All your theme settings have been restored'));
    }
    if(isset($form_state['values']['restore_file_media_upload'])) {

    }

}

/**
 * Default theme settings
 */
function _solveto_theme_default_settings ($theme_settings) {
    $default_settings = array();
    foreach ($theme_settings as $key => $setting) {
        $default_settings[$key] = null;
    }
    $default_settings['toggle_logo'] = 1;
    $default_settings['toggle_name'] = 1;
    $default_settings['toggle_slogan'] = 1;
    $default_settings['toggle_node_user_picture'] = 1;
    $default_settings['toggle_comment_user_picture'] = 1;
    $default_settings['toggle_comment_user_verification'] = 1;
    $default_settings['toggle_fvicon'] = 1;
    $default_settings['toggle_main_menu'] = 1;
    $default_settings['toggle_secondary_menu'] = 1;
    $default_settings['default_logo'] = 1;
    $default_settings['default_favicon'] = 1;
    $default_settings['css3_textarea'] = 0;
    $default_settings['webclip_precomp'] = 1;
    $default_settings['skins'] = 'default';
    $default_settings['typo_heading_style_enable'] = 0;
    $default_settings['header_background_type'] = 'video';
    $default_settings['header_video_play'] = 0;
    $default_settings['menu_custom_enable'] = 0;
    $default_settings['menu_sticky'] = 1;
    $default_settings['menu_bg_color'] = '';
    $default_settings['menu_link_color'] = '';
    $default_settings['menu_link_hover_color'] = '';
    $default_settings['nf_text'] = 'Oops! I couldnt find that one.<br>Click the button below to go back home.';

    $default_settings['nodetitle_enable'] = 0;
    $default_settings['typo_view_title_enable'] = 0;
    $default_settings['maintenance_message'] = '<p><span>Our awesome website is</span> <br> Under construction </p>';
    $default_settings['footer_text'] = '&copy; 2014 All Rights Reserved. Made with <i class="fontello icon-heart"></i> by <a href="http://tonybogdanov.com" target="_blank">TonyBogdanov</a> . Drupal Theme by <a href="http://themeforest.com/user/6ixfire">6ixfire</a>';

    return $default_settings;
}
/**
 * Analys goole link to get font information
 */
function _solveto_process_google_web_font($fonts) {
    if (strpos($fonts, '@import url(') !== FALSE) {
        preg_match("/http:\/\/\s?[\'|\"]?(.+)[\'|\"]?\s?(\)|\')/Uix", $fonts, $ggwflink);
    }

    preg_match('/([^\?]+)(\?family=)?([^&\']+)/i', $fonts, $matches);
    $gfonts = explode("|", $matches[3]);

    for ($i = 0; $i < count($gfonts); $i++) {
        $gfontsdetail = explode(":", $gfonts[$i]);
        $gfontname = str_replace("+", " ", $gfontsdetail['0']);
        $fontarray[] = $gfontname;
        if (array_key_exists('1', $gfontsdetail)) {
            $tmpft = explode(",", $gfontsdetail['1']);
            $gfontweigth[$i] = "";
            for ($j = 0; $j < count($tmpft); $j++) {
                if (preg_match("/italic/i", $tmpft[$j])) {
                    $gfontstyle = "i";
                } else {
                    $gfontstyle = "n";
                }
                $tmpw = str_replace("italic", "", $tmpft[$j]);
                $seperator = ",";

                if ($j == (count($tmpft) - 1)) {
                    $seperator = "";
                }

                if ($tmpw) {
                    $gfontweigth[$i] .= $gfontstyle . str_replace("00", "", $tmpw) . $seperator;
                } else {
                    $gfontweigth[$i] .= "n4" . $seperator;
                }
            }
        } else {
            $gfontweigth[$i] = "n4";
        }
        $fontvars[] = array(
            'CSS' => '"' . $gfontname . '"',
            'Weight' => $gfontweigth[$i],
        );
    }

    return array($fontarray, $fontvars);
}
/**
 * Load font configure
 */
function load_font_configure() {
    $theme_default = variable_get('theme_default', 'Bartik');
    $fontarray = array(
        t('Default'),
        t('Arial'),
        t('Verdana'),
        t('Trebuchet MS'),
        t('Georgia'),
        t('Times New Roman'),
        t('Tahoma'),
    );

    $fontvars = array(
        array('CSS' => '', 'Weight' => 'n4'),
        array('CSS' => 'Arial, sans-serif', 'Weight' => 'n4, n7, i4, i7'),
        array('CSS' => 'Verdana, Geneva, sans-serif', 'Weight' => 'n4, n7, i4, i7'),
        array('CSS' => 'Trebuchet MS, Tahoma, sans-serif', 'Weight' => 'n4, n7, i4, i7'),
        array('CSS' => 'Georgia, serif', 'Weight' => 'n4, n7, i4, i7'),
        array('CSS' => 'Times New Roman, serif', 'Weight' => 'n4, n7, i4, i7'),
        array('CSS' => 'Tahoma, Geneva, Verdana, sans-serif', 'Weight' => 'n4, n7, i4, i7'),
    );
    $google_font = theme_get_setting('googlewebfonts','solveto');
    if ($google_font != '') {
        $result = _solveto_process_google_web_font($google_font);
        add_font_style($result, $fontarray, $fontvars);
    }
    $typekit = theme_get_setting('typekit_id','solveto');;

    if ($typekit != '') {
        $result = _solveto_process_typekit_font($typekit);
        add_font_style($result, $fontarray, $fontvars);
    }

    return array($fontarray, $fontvars);
}

function add_font_style($results, &$font_array, &$font_vars) {
    if (is_array($results)) {
        foreach ($results[0] as $id => $font_name) {
            $key = array_search($font_name, $font_array);
            if ($key === FALSE) {
                $font_array[] = $font_name;
                $font_vars[] = $results[1][$id];
            } else {
                $font_vars[$key] = $results[1][$id];
            }
        }
    }
}

/**
 * @param $directory
 * @return array
 * Get Directory List
 */
function getDirectoryList ($directory)
{

    // create an array to hold directory list
    $results = array();

    // create a handler for the directory
    $handler = opendir($directory);

    // open directory and walk through the filenames
    while ($file = readdir($handler)) {

        // if file isn't this directory or its parent, add it to the results
        if ($file != "." && $file != "..") {
            $results[] = $file;
        }

    }

    // tidy up: close the handler
    closedir($handler);

    // done!
    return $results;

}
/**
 * @param $haystack
 * @param $needle
 * @param int $offset
 * @return bool
 * Check string in string
 */
function strposa($haystack, $needle, $offset=0) {
    if(!is_array($needle)) $needle = array($needle);
    foreach($needle as $query) {
        if(strpos($haystack, $query, $offset) !== false) return true; // stop on first true result
    }
    return false;
}
function icon_default_dialog() {

    $options = array();
    $icon_default_value = array();
    if(module_exists('icon')) {
        foreach (icon_bundles() as $bundle_name => $bundle) {
            if (!$bundle['status']) {
                continue;
            }
            foreach ($bundle['icons'] as $icon_key => $icon_value) {
                $icon_name = is_string($icon_key) ? $icon_key : $icon_value;
                if (is_array($icon_value) && isset($icon_value['name'])) {
                    $icon_name = $icon_value['name'];
                }
                $icon_title = is_string($icon_value) ? $icon_value : $icon_name;
                if (is_array($icon_value) && isset($icon_value['title'])) {
                    $icon_title = $icon_value['title'];
                }
                if(isset($bundle['name'])) {
                    $options[$bundle['title']][$bundle['name'] . '|' . $icon_name] = $icon_title;
                }
            }
            $icon_default_value = $options;
        }
        $icon_mark_up = '';
        $icon_fake_markup = '<ul class="list-icon">';
        foreach($icon_default_value as $key => $value) {
            $icon_mark_up .= '<option selected="selected" value="">- No Icon -</option><optgroup label="'.$key.'">';
            foreach ($icon_default_value[$key] as $key2 => $value2) {
                $fake_icon_explode = explode("|",$key2);
                $icon_fake_markup .= '<li><a href="#'.$fake_icon_explode[1].'" class="fake-icon" alt="'.$fake_icon_explode[1].'" icon-name="'.$fake_icon_explode[1].'" data-bundle="'.$fake_icon_explode[0].'" data-icon="'.$key2.'"><i class="'.$fake_icon_explode[0].' '.$fake_icon_explode[1].'"></i></a></li>';
                $icon_mark_up .= '<option value="'.$key2.'">'.$value2.'</option>';
            }
            $icon_mark_up .= '</optgroup>';
        }
        $icon_fake_markup .= '</ul>';
        drupal_add_js(array('icMarkUp' => $icon_mark_up),'setting');
        drupal_add_js(array('icFake' => $icon_fake_markup),'setting');
    }

}
function theme_path() {
    $theme_path = drupal_get_path('theme','solveto');
    return $theme_path;
}
function get_option_icon(){
    $options = array();
    $icon_default_value = array();
    if(module_exists('icon')) {
        foreach (icon_bundles() as $bundle_name => $bundle) {
            if (!$bundle['status']) {
                continue;
            }
            $class = isset($bundle['settings']['class']) ? $bundle['settings']['class'] : 'fa';
            foreach ($bundle['icons'] as $icon_key => $icon_value) {
                $icon_name = is_string($icon_key) ? $icon_key : $icon_value;
                if (is_array($icon_value) && isset($icon_value['name'])) {
                    $icon_name = $icon_value['name'];
                }
                $icon_title = is_string($icon_value) ? $icon_value : $icon_name;
                if (is_array($icon_value) && isset($icon_value['title'])) {
                    $icon_title = $icon_value['title'];
                }
                $options[$bundle['title']][$class . '|' . $icon_name] = $icon_title;
            }
            $icon_default_value = $options;
        }
    }
    return $icon_default_value;
}
